// KeyGeneration.cpp : Defines the entry point for the DLL application.
//

#include <windows.h>
#include "KeyGenAlgoInterfaceEx.h"
#include "aes_cbc_cmac.h"


BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    return TRUE;
}



KEYGENALGO_API VKeyGenResultEx GenerateKeyEx(
      const unsigned char*  iSeedArray,     /* Array for the seed [in] */
      unsigned int          iSeedArraySize, /* Length of the array for the seed [in] */
      const unsigned int    iSecurityLevel, /* Security level [in] */
      const char*           iVariant,       /* Name of the active variant [in] */
      unsigned char*        ioKeyArray,     /* Array for the key [in, out] */
      unsigned int          iKeyArraySize,  /* Maximum length of the array for the key [in] */
      unsigned int&         oSize           /* Length of the key [out] */
      )
{
    unsigned char key_constant_level01[16U] = {0xBC,0x90,0xE2,0x06,0xC8,0x1C,0xD4,0x8E,0xB6,0x50,0x4D,0xB4,0x3C,0x01,0x6B,0xE0};
    unsigned char key_constant_level11[16U] = {0x68,0x94,0x44,0x53,0x5F,0x9D,0x4E,0x61,0x13,0xAE,0x8A,0x73,0xDB,0xC2,0xDC,0x4E};

    if (iSeedArraySize > iKeyArraySize)
    {
      return KGRE_BufferToSmall;
    }
    else if(iSeedArraySize != 16)
    {
      return KGRE_VariantInvalid;
    }

    if(iSecurityLevel == 0x01)
    {
      AES_CMAC(key_constant_level01,iSeedArray,16U,ioKeyArray);
    }
    else if(iSecurityLevel == 0x11)
    {
      AES_CMAC(key_constant_level11,iSeedArray,16U,ioKeyArray);
    }
    else
    {
      return KGRE_SecurityLevelInvalid;
    }
    
    oSize=iSeedArraySize;
    
  return KGRE_Ok;
}


